/*
 * File:    PropertiesImpl.java
 * Created: 08-May-2007
 * Version: $Id$
 *
 * COPYRIGHT (C) 2007, Bitgate Software, LLC.  All Rights Reserved.
 *
 * software@bitgatesoftware.com
 */

package com.bitgate.util.socket;

import java.util.HashMap;

/**
 * This is an abstract class that implements the simple interface to retrieve and store object properties 
 * attached to a currently active <code>ClientChannel</code> object.  It can be used to attach objects
 * to client connections that are running - information that pertains only to that client.  This class
 * implementation is thread-safe, and does not use the concurrency model.
 * 
 * @author kenji
 * @version $Id$
 */
public abstract class AbstractSocketProperties implements PropertiesInterface
{
	private final HashMap<String, Object> objectProperties;
	
	/**
	 * Implementation constructor for the properties entries.
	 */
	public AbstractSocketProperties()
	{
		this.objectProperties = new HashMap<String, Object>();
	}
	
	/**
	 * Assigns a new property to a <code>ClientChannel</code> object.
	 * 
	 * @param property The <code>String</code> containing the property name.
	 * @param obj The <code>Object</code> to apply to it.
	 */
	public void addProperty(String property, Object obj)
	{
		synchronized(this.objectProperties) {
			this.objectProperties.put(property, obj);
		}
	}
	
	/**
	 * Retrieves the object bound to the property specified.
	 * 
	 * @param property The <code>String</code> containing the property name.
	 * @return <code>Object</code> containing the property attachment.
	 */
	public Object getProperty(String property)
	{
		synchronized(this.objectProperties) {
			return this.objectProperties.get(property);
		}
	}
	
	/**
	 * Removes the property attached to the <code>ClientChannel</code> object.
	 * 
	 * @param property The <code>String</code> containing the property name.
	 * @return <code>Object</code> containing the property attachment after removal.
	 */
	public Object removeProperty(String property)
	{
		synchronized(this.objectProperties) {
			return this.objectProperties.remove(property);
		}
	}
}